//
//  LoginViewController.m
//  FNMenu
//
//  Created by 航汇聚科技 on 2018/9/7.
//  Copyright © 2018年 Yi Zhou. All rights reserved.
//

#import "LoginViewController.h"
#import "NSDictionary+Safety.h"
#import "NetManager.h"
#import "User.h"
@interface LoginViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *loginBackImgView;
@property (weak, nonatomic) IBOutlet UIVisualEffectView *effectView;
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UIView *loginContentView;

@end

@implementation LoginViewController

#pragma mark - lifeCycle
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.loginBackImgView.userInteractionEnabled = YES;
    self.effectView.userInteractionEnabled = YES;
    self.loginBackImgView.backgroundColor = [UIColor colorWithRed:206./255. green:203./255. blue:188./255. alpha:0.5];
    [self.textField becomeFirstResponder];
    
    self.loginContentView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    self.loginContentView.layer.shadowOffset = CGSizeMake(2, 2);
    self.loginContentView.layer.shadowRadius = 3;
    self.loginContentView.layer.shadowOpacity = .7;
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    return [textField resignFirstResponder];
}
#pragma mark - event response
- (IBAction)tapBackImgView:(UITapGestureRecognizer *)sender {
    [self.textField resignFirstResponder];
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)loginAction:(UIButton *)sender {
    [self.textField resignFirstResponder];
    if (self.textField.text.length != 11) {
        return;
    }
    
    [[NetManager defaultNetManager] fetchNetDataWithURLStr:@"home/users/register" params:@{@"phone":self.textField.text} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"%@",responseObject);
        [User saveUserId:[[responseObject safeObjectForKey:@"show_data"] safeObjectForKey:@"id"]];
        [self dismissViewControllerAnimated:YES completion:nil];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
}
#pragma mark - public
+ (instancetype)loginVCFromStoryBoard {
    return [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginVC"];
}
@end
